import axios from 'axios'
import store from '../store'
import router from '@/router'
const request = axios.create({
  baseURL: 'https://shop.fed.lagounews.com/api/'
})
// 请求拦截器中进行token设置
request.interceptors.request.use(config => {
  const { token } = store.state.user
  config.headers.Authorization = 'Bearer ' + token
  return config
})

// 响应拦截器中进行失败请求的处理
request.interceptors.response.use(config => {
  // console.log(config)
  if (config.data.status === 410000) {
    // 跳转登陆页面
    router.push({
      name: 'login',
      query: {
        redirect: router.currentRoute.fullPath
      }
    })
  }
  return config
})
export default request
